package infostroy.bookagolf.components.renderer;


import infostroy.bookagolf.common.Constants.Colors;
import infostroy.bookagolf.common.Constants.Icons;
import infostroy.bookagolf.common.helpers.ImageHelper;
import sun.swing.table.DefaultTableCellHeaderRenderer;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import java.awt.*;

/**
 * Created by Andrew on 14.02.14.
 */
public class GolfHeaderRenderer extends DefaultTableCellHeaderRenderer {


    private boolean showListIcon;
    private Border border = BorderFactory.createMatteBorder(0, 0, 0, 0, Colors.TABLE_HEADER_BACKGROUND_COLOR);

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        if (table.getColumnCount() - 1 == column && this.isShowListIcon()) {
            label.setIcon(new ImageIcon(ImageHelper.getInstance().loadImage(Icons.TABLE_LIST_HEADER_ICON)));
        } else {
            label.setForeground(Colors.TABLE_HEADER_TEXT_COLOR);
        }

        label.setHorizontalAlignment(JLabel.LEFT);
        if (column == 0) {
            label.setBorder(new EmptyBorder(0, 20, 0, 0));
        } else {
            label.setBorder(border);
        }
        label.setBackground(Colors.TABLE_HEADER_BACKGROUND_COLOR);


        return label;
    }

    public boolean isShowListIcon() {
        return showListIcon;
    }

    public void setShowListIcon(boolean showListIcon) {
        this.showListIcon = showListIcon;
    }
}
